import Vue from 'vue'
import Vuex from 'vuex'
import menu from './modules/menu';
import role from './modules/role';
import admin from './modules/admin';
import cate from './modules/cate';
import specs from './modules/specs';
import goods from './modules/goods';
import member from './modules/member';
import banner from './modules/banner';
import seckill from './modules/seckill';

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    userInfo: sessionStorage.getItem('userInfo') ? JSON.parse(sessionStorage.getItem('userInfo')) : null
  },
  getters: {
  },
  mutations: {
    changeUserInfo(state, data) {
      if (!data) {
        sessionStorage.removeItem('userInfo');
        return;
      }
      state.userInfo = data;
      sessionStorage.setItem('userInfo', JSON.stringify(data));
    }
  },
  actions: {
    setUserInfo(context, data) {
      context.commit('changeUserInfo', data);
    }
  },
  modules: {
    menu,
    role,
    admin,
    cate,
    specs,
    goods,
    member,
    banner,
    seckill
  }
})
